<?php

namespace bc\model;

use bc\ar\MActiveRecord;

class ProductModel extends MActiveRecord
{
	public $autoId = 'product_id';
	public static function tableName()
	{
		return '{{%product}}';
	}
	
	/**
	 *
	 * @param array $ids        	
	 */
	public function getProductCollection(array $ids)
	{
		$ar = $this->find ()->select ( $this->columns )->where ( ['in', 'product_id', $ids] );
		
		if ($this->sort == null)
			$ar->orderBy ( $this->autoId . ' DESC' );
		else
			$ar->orderBy ( $this->sort );
		return $ar->asArray ()->all ();
	}
        
        public function getRowByIds($id)
        {
            $this->columns = "bc_product.product_id , bc_product.product_name, bc_product.short_description, bc_product.description, bc_product.market_price,bc_product.product_price,bc_product.category_id";
            $ar = $this->find()->select( $this->columns )->where(['bc_product.product_id'=> $id]);
            return $ar->asArray()->One();
        }
        
        public function getPrimaryKeyByProductId($id) 
        {
            $sql = "SELECT `id` FROM `bc_product`  WHERE  `product_id` = $id";

            $data = self::findBySql( $sql )->asArray()->one();
            //var_dump($data);die();
            return $data;
            
        }
        /*
         * 获取产品总数
         */
            public function getTotal($params='1=1')
	{       
		if ($params) {
			return $this->find()->where ( $params )->count();
		}else{
			return $this->find()->select( $this->columns )->count();
		}
	}
        
          /*
         * 获取产品列表
         */
        public function getProductInfo(){
            $this->columns = 'bc_product.product_id , bc_product.product_name , bc_product.is_sale , bc_product.category_id';
           
            $ar = $this->find()->select( $this->columns );
            return $ar->asArray ()->all ();
        }
      

}

